library(dplyr)
library(knitr)
library(maptools)
library(rgdal)
library(TreeSegmentation)
library(sp)
library(ggplot2)
library(rgl)
library(clue)
library(lidR)
knit_hooks$set(webgl = hook_webgl)
opts_chunk$set(warning=F,message=F)
#set color ramp for treeID
col = pastel.colors(200)
shps<-list.files("/Users/ben/Dropbox/Weecology/ITCs/",pattern=".shp",full.names = T)
itcs<-lapply(shps,readOGR,verbose=F)
names(itcs)<-sapply(itcs,function(x){
id<-unique(x$Plot_ID)
#x@proj4string<-CRS("+init=epsg:32617")
return(x)
})
ground_truth<-itcs[[20]]
fname<-get_tile_filname(ground_truth,basename = "2014_OSBS_1_",extension = "_colorized.laz")
tile<-readLAS(paste("../data/2015/cropped_",fname,sep=""))
tile@crs<-CRS("+init=epsg:32617")
plot(tile)
You must enable Javascript to view this page properly.
plot(extent(tile),col='red')
plot(extent(ground_truth),col='blue',add=T)
silva<-silva2016(tile=tile,output="all")
## [1] "Computing Ground Model"
## [1] "Computing Canopy Model"
## [1] "Clustering Trees"
## user system elapsed
## 7.953 0.123 8.224
## [1] "Creating tree polygons"
dalponte<-dalponte2016(tile=tile,output="all")
## [1] "Computing Ground Model"
## [1] "Computing Canopy Model"
## [1] "Clustering Trees"
## user system elapsed
## 5.910 0.098 6.111
## [1] "Creating tree polygons"
li<-li2012(tile=tile,output="all")
## [1] "Computing Ground Model"
## [1] "Computing Canopy Model"
## [1] "Clustering Trees"
## user system elapsed
## 0.091 0.003 0.099
## [1] "Creating tree polygons"
watershed_result<-watershed(tile=tile,output="all")
## [1] "Computing Ground Model"
## [1] "Computing Canopy Model"
## [1] "Clustering Trees"
## user system elapsed
## 6.980 0.094 7.168
## [1] "Creating tree polygons"
plot(silva$tile,color="treeID",col=col)
You must enable Javascript to view this page properly.
plot(ground_truth,col='red')
plot(silva$convex,add=T)
#plot(dalponte$convex,add=T)
chm=canopy_model(silva$tile)
plot(chm,ext=extent(ground_truth))
plot(ground_truth,add=T,col='red')
plot(silva$convex,add=T)
Okay that’s not great, but let’s keep going for the moment.
Silva v Dalponte
plot(silva$convex)
plot(dalponte$convex,add=T,col=rgb(0,0,255,20,maxColorValue=255))
plot(silva$convex)
plot(dalponte$convex,add=T,col=rgb(0,0,255,20,maxColorValue=255))
plot(li$convex,add=T,col=rgb(0,0,255,20,maxColorValue=255))
Li versus watershed
plot(li$convex)
plot(watershed_result$convex,add=T,col=rgb(0,0,255,20,maxColorValue=255))
ptlist<-list(silva=silva$tile,li=li$tile,dalponte=dalponte$tile,watershed=watershed_result$tile)
consensus_result<-consensus(ptlist=ptlist,method="majority")
consensus_polygons<-get_convex_hulls(consensus_result,consensus_result@data$treeID)
plot(consensus_polygons,col=rgb(0,0,255,20,maxColorValue=255))
#plot(consensus_result,color="treeID",col=col)
You must enable Javascript to view this page properly.
plot(silva$convex)
plot(dalponte$convex)
plot(li$convex)
plot(consensus_polygons,add=T,col=rgb(0,0,255,40,maxColorValue=255))
How many tree predictions
library(pander)
unique_total<-sapply(c(ptlist,consensus_result),function(x) length(unique(x@data$treeID)))
df<-data.frame(Algorthm=c(names(ptlist),"consensus"),Total_Trees=as.numeric(unique_total))
pandoc.table(df,style="rmarkdown")
##
##
## | Algorthm | Total_Trees |
## |:---------:|:-----------:|
## | silva | 322 |
## | li | 502 |
## | dalponte | 321 |
## | watershed | 243 |
## | consensus | 321 |
Each tree is assigned based on the maximum overlap. Pairwise membership is done using a Hungarian Algorithm. See clue::solve_LSAP.
assignment<-assign_trees(ground_truth,prediction=silva$convex)
#loop through assignments and get jaccard statistic for each assignment pair
statdf<-calc_jaccard(assignment=assignment,ground_truth = ground_truth,prediction=silva$convex)
ggplot(statdf) + geom_histogram(aes(IoU)) + labs(x="Intersection over union") + theme_bw()
mean(statdf$IoU)
## [1] 0.219998
median(statdf$IoU)
## [1] 0.2294968
results<-evaluate(ground_truth=itcs[[1]],algorithm = c("silva","dalponte","li"),path_to_tiles="/Users/ben/Dropbox/Weecology/NEON/cropped_",compute_consensus = T)
## [1] "Silva"
## [1] "Computing Ground Model"
## [1] "Computing Canopy Model"
## [1] "Clustering Trees"
## user system elapsed
## 9.267 0.068 9.369
## [1] "Creating tree polygons"
## [1] "Dalponte"
## [1] "Computing Ground Model"
## [1] "Computing Canopy Model"
## [1] "Clustering Trees"
## user system elapsed
## 5.721 0.045 5.787
## [1] "Creating tree polygons"
## [1] "li"
## [1] "Computing Ground Model"
## [1] "Computing Canopy Model"
## [1] "Clustering Trees"
## user system elapsed
## 0.176 0.003 0.182
## [1] "Creating tree polygons"
## [1] "consensus"
ggplot(results,aes(x=IoU,fill=Method)) + geom_histogram(position = position_dodge()) + theme_bw()
results %>% group_by(Method) %>% summarize(mean=mean(IoU),median=median(IoU))
## # A tibble: 4 x 3
## Method mean median
## <chr> <dbl> <dbl>
## 1 consensus 0.309 0.354
## 2 dalponte 0.345 0.402
## 3 li 0.359 0.374
## 4 silva 0.348 0.338
system.time(results_all<-evaluate_all(itcs=itcs,algorithm = c("dalponte","silva","li","watershed"),path_to_tiles="/Users/ben/Dropbox/Weecology/NEON/cropped_",cores=4,extra=F,compute_consensus=F))
## user system elapsed
## 0.196 0.016 2060.436
ggplot(results_all,aes(x=IoU,fill=Method)) + geom_histogram(position = position_dodge()) + theme_bw()
results_all %>% group_by(Method) %>% summarize(mean=mean(IoU),median=median(IoU))
## # A tibble: 4 x 3
## Method mean median
## <chr> <dbl> <dbl>
## 1 dalponte 0.0960 0.
## 2 li 0.0997 0.
## 3 silva 0.102 0.
## 4 watershed 0.0746 0.